import util.GuiImg;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Get extends JPanel implements ActionListener {
    /**
     * 取款
     */
    private Icon atmIcon9 = GuiImg.getIcon("/imgs/buttonSure.jpg");
    private JButton btnlogin8 = new JButton(atmIcon9);
    private Atm frame;
    private JTextField textField1;

    public Get(Atm frame) {
        this.frame = frame;
        this.setLayout(null);
        //单行输入框
        textField1 = new JTextField();
        textField1.setBounds(250, 200, 250, 30);
        this.add(textField1);
        //确认按钮
        this.setOpaque(false);
        btnlogin8.setBounds(330, 300, 100, 40);
        this.add(btnlogin8);
        btnlogin8.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnlogin8) {
            if (Double.valueOf(textField1.getText()) <= frame.getUserArray().get(frame.getIndex()).getMoney()) {
                frame.getUserArray().get(frame.getIndex()).setMoney(frame.getUserArray().get(frame.getIndex()).getMoney() - Double.valueOf(textField1.getText()));
                JOptionPane.showMessageDialog(this, "取款成功");
                frame.itin();
            } else {
                JOptionPane.showMessageDialog(this, "余额不足");
            }
            frame.switchPanel("菜单");
        }
    }
}
